#!/usr/bin/env python

import sys
import os

CMD = 'sobjc4gcc'
SHORT_OPTS = ['-W', '-E', '-t', '-S', '-c', '-w', '-I', '-L', '-l']
FLAGS = ['inline-cache', 'no-inline-cache',
         'dispatch-table', 'no-dispatch-table',
         'no-nil-receivers', 'no-strict-message']

args = [CMD]
sys.argv.pop(0)
next_arg = False
for i in xrange(0, len(sys.argv)):
    arg = sys.argv[i]
    if next_arg:
        next_arg = False
        args.append(arg)
    elif arg.startswith('-f'):
        if arg[2:] in FLAGS:
            arg = '--' + arg[2:]
        args.append(arg)
    elif arg == '-v':
        args.append(arg)
        args.append('--cc-verbose')
    elif arg in SHORT_OPTS:
        next_arg = True
    elif arg[:2] in SHORT_OPTS:
        args.append(arg)
    elif arg.startswith('-'):
        args.append('-X')
        args.append(arg)
    else:
        args.append(arg)

os.execvp(CMD, args)

